#include <linux/bitmap.h>

#define BITMAP_WEIGHT(FETCH, bits)                                      \
	({                                                                  \
		unsigned int __bits = (bits), idx, w = 0;                       \
                                                                        \
		for (idx = 0; idx < __bits / BITS_PER_LONG; idx++)              \
			w += hweight_long(FETCH);                                   \
                                                                        \
		if (__bits % BITS_PER_LONG)                                     \
			w += hweight_long((FETCH) & BITMAP_LAST_WORD_MASK(__bits)); \
                                                                        \
		w;                                                              \
	})

unsigned int __bitmap_weight(const unsigned long *bitmap, unsigned int bits)
{
	return BITMAP_WEIGHT(bitmap[idx], bits);
}
